import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
import { defineStore } from 'pinia'

const store = createPinia()
store.use(
  createPersistedState({
    storage: {
      getItem: uni.getStorageSync,
      setItem: uni.setStorageSync,
    },
  }),
)

export default store

// 模块统一导出
export * from './user'

export const useUserStore = defineStore('user', {
  state: () => ({
    isLogin: false,
    userInfo: {}
  }),
  actions: {
    login(userInfo) {
      this.isLogin = true;
      this.userInfo = userInfo;
    },
    logout() {
      this.isLogin = false;
      this.userInfo = {};
    }
  }
});
